package com.qf.common.response;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.io.Serializable;
import java.util.List;

@JsonSerialize
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class Response<T> implements Serializable{

    private Integer code;
    private String message;
    private Boolean status;
    private T data;

    public Response(Integer code, String message, Boolean status, T data) {
        this.code = code;
        this.message = message;
        this.status = status;
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Boolean getStatus() {
        return status;
    }

    public void setStatus(Boolean status) {
        this.status = status;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static <T> Response<T> success(T data) {
        return new Response<>(ResponseEnum.SUCCESS.getCode(), null, ResponseEnum.SUCCESS.getStatus(),data);
    }

    public static <T> Response<T> success() {
        return new Response<>(ResponseEnum.SUCCESS.getCode(), null, ResponseEnum.SUCCESS.getStatus(),null);
    }

    public static <T> Response<T> fail(T data) {
        return new Response<>(ResponseEnum.FAIL.getCode(), null, ResponseEnum.FAIL.getStatus(),data);
    }

    public static <T> Response<T> fail(String msg) {
        return new Response<>(ResponseEnum.FAIL.getCode(), msg, ResponseEnum.FAIL.getStatus(),null);
    }
}
